<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/19
 * Time: 14:27
 */

namespace app\server;
use rap\db\DB;

class peccancyData
{
    /**
     * 添加违章信息日志
     * @param $data
     * @return \rap\db\Insert|string
     */
    public function addPecInfo($data) {

        $res = DB::insert('mp_peccancy_log', $data);

        return $res;
    }

    /**
     * @param $where
     * @param $field
     * @return mixed|null
     */
    public function getUserPecInfo($where, $field) {

        $data = DB::select('mp_peccancy_log')->where($where)->fields($field)->order('create_time desc')->cache()->find();

        if ($data) {
            $data['log_data'] = unserialize($data['log_data']);
        }

        return $data;
    }

    public function insertPecDataInfo ($data) {

        $res = DB::insert('mp_pecc_data', $data);

        return $res;
    }

    public function getUserPecDataInfo($where, $field = "*") {

        $data = DB::select('mp_pecc_data')->where($where)->fields($field)->cache()->find();

        if ($data) {
            $data['log_data'] = unserialize($data['log_data']);
        }

        return $data;
    }

    public function updateUserPecInfo ($where,$data) {

        $sql = DB::update('mp_peccancy_data');
        foreach ($data as $k => $v) {
            $sql = $sql->set($k, $v);
        }
        $res =$sql->where($where)->excuse();

        return $res;
    }

    /**
     * 获取违章历史列表
     * @param $where
     * @param $field
     * @param $page
     * @param $limit
     * @return mixed
     */
    public function getUserPecList ($where, $field, $page = 1, $limit = 20) {

        $data = DB::select("mp_peccancy_log")->where($where)->fields($field)->page($page , $limit)->order('create_time desc')->cache()->findAll();

        return $data;
    }


}